package client; 

import java.net.*;
import java.io.*;

public class Client {
	private Socket connessione;
	private String name;
	private BufferedReader dalServer;
	private PrintStream alServer;
	
	public Client(String name){
		this.name=name;
		BufferedReader t = new BufferedReader (new InputStreamReader(System.in));
		try{
			System.out.println("Inserire indirizzo Server: ");
			String indirizzo = t.readLine();
			connessione = new Socket(indirizzo, 1000);
			dalServer = new BufferedReader(new InputStreamReader(connessione.getInputStream()));
			alServer = new PrintStream(connessione.getOutputStream());
			
		}
		catch (IOException e){
			System.out.println(e);
			}
		} //end client
	
	public void conversazione(){
		String messaggio = "";
		BufferedReader t = new BufferedReader(new InputStreamReader(System.in));
		try{
			while (!messaggio.equals("/logout")) {
				messaggio=dalServer.readLine();
				System.out.println(messaggio);
				if (!messaggio.equals("/logout")){
					messaggio=t.readLine();
					alServer.println(name+" scrive: "+messaggio);
				}
				
				}//end while
			connessione.close();
			}//end try
		
		catch(IOException e){
			System.out.println("Connessione Interrotta");
			}
	
	} //end conversazione()
	
	}
	

